/****************************************************************
 *
 *  Add some comments here
 * 
 * 
 * 
 * 
 ***************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace Wicresoft.OmsClient
{
    class SyncConfigManage
    {
        private static string _RegPath;

        public static string RegPath
        {
            get { return SyncConfigManage._RegPath; }
            set { SyncConfigManage._RegPath = value; }
        }

        private static bool SaveData(string key, string data)
        {
            try
            {
                RegistryKey rsg = Registry.CurrentUser.OpenSubKey(_RegPath, true);
                rsg.SetValue(key, data);
                rsg.Close();
                return true;
            }
            catch (Exception ex)
            {
                Logger.Exception("SyncConfigManage.SaveData Exception", ex);
                return false;
            }
        }

        private static string GetData(string key)
        {
            try
            {
                RegistryKey rsg = Registry.CurrentUser.OpenSubKey(_RegPath, true);
                string data = rsg.GetValue(key) != null ? rsg.GetValue(key).ToString().Trim() : string.Empty;
                rsg.Close();
                return data;
            }
            catch (Exception ex)
            {
                Logger.Exception("SyncConfigManage.GetData Exception", ex);
                return "";
            }
        }

        public static string ProviderUrl
        {
            get
            {
                return GetData("ProviderUrl");
            }
            set
            {
                SaveData("ProviderUrl", value);
            }
        }

        public static string Email
        {
            get
            {
                return GetData("Email");
            }
            set
            {
                SaveData("Email", value);
            }
        }

        public static string Mobile
        {
            get
            {
                return GetData("Mobile");
            }
            set
            {
                SaveData("Mobile", value);
            }
        }

        /// <summary>
        /// second
        /// </summary>
        public static int SyncInterval
        {
            get
            {
                try
                {
                    return Convert.ToInt32(GetData("SyncInterval"));
                }
                catch (Exception ex)
                {
                    Logger.Exception("SyncConfigManage.SyncInterval ", ex);
                    SyncInterval = 60;
                    return 60;
                }
            }
            set
            {
                SaveData("SyncInterval", value.ToString());
            }
        }

        public static string EnableCalendarSync
        {
            get
            {
                return GetData("EnableCalendarSync");
            }
            set
            {
                SaveData("EnableCalendarSync", value);
            }
        }

        public static string EnableContactSync
        {
            get
            {
                return GetData("EnableContactSync");
            }
            set
            {
                SaveData("EnableContactSync", value);
            }
        }

        public static string UserName
        {
            get
            {
                return GetData("UserName");
            }
            set
            {
                SaveData("UserName", value);
            }
        }

        public static string Password
        {
            get
            {
                return GetData("Password");
            }
            set
            {
                SaveData("Password", value);
            }
        }
    }
}
